#ifndef __FLOAT_H__
#define __FLOAT_H__

#include "trap.h"

typedef int FLOAT;

static inline int F2int(FLOAT a) {
	int result = a >> 16;
	return result;
}

static inline FLOAT int2F(int a) {
	int sign = (a < 0 ? 0x80000000 : 0x0);
	return (sign | (0x7fffffff & (a << 16)));
}

static inline FLOAT F_mul_int(FLOAT a, int b) {
	int sign = (a & 0x80000000) ^ (b & 0x80000000);
	long long la = a, lb = b;
	int result = (la * lb);
	result = sign | (result & 0x7fffffff);
	return result;
}

static inline FLOAT F_div_int(FLOAT a, int b) {
	/*int result;
	int ext = (a < 0 ? 0xffffffff : 0x0);
	asm volatile (
			"movl %1, %%edx;"
			"movl %2, %%eax;"
			"movl %3, %%ebx;"
			"idivl %%ebx;"
			:"=a"(result):"g"(ext),"g"(a),"g"(b));
	return result;
	*/
	return a/b;
}

FLOAT f2F(float);
FLOAT F_mul_F(FLOAT, FLOAT);
FLOAT F_div_F(FLOAT, FLOAT);
FLOAT Fabs(FLOAT);
FLOAT sqrt(FLOAT);
FLOAT pow(FLOAT, FLOAT);

// used when calling printf/sprintf to format a FLOAT argument
#define FLOAT_ARG(f) (long long)f

void init_FLOAT_vfprintf(void);

#endif
